package com.byxy.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.byxy.dao.LyAgencyDao;
import com.byxy.entity.LyAgency;
@Repository
public class LyAgencyDaoImpl implements LyAgencyDao {

	@Resource
	private SessionFactory sessionFactory;
	@Override
	public List<LyAgency> find() {
		
		return sessionFactory.getCurrentSession().createQuery("from Forder").list();
	}

	@Override
	public void add(LyAgency a) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().save(a);
	}

	@Override
	public LyAgency getById(Integer id) {
		// TODO Auto-generated method stub
		return (LyAgency) sessionFactory.getCurrentSession().get(LyAgency.class, id);
	}

	@Override
	public void update(LyAgency a) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().update(a);
	}

	@Override
	public void deleteById(Integer id) {
		LyAgency a=new LyAgency();
		a.setId(id);
		sessionFactory.getCurrentSession().delete(a);
	}

	@Override
	public List<LyAgency> find(int curPage, int pageCount) {
		// TODO Auto-generated method stub
		return sessionFactory.getCurrentSession().createQuery("from Forder")
				.setFirstResult((curPage-1)*pageCount)
				.setMaxResults(pageCount)
				.list();
	}

	@Override
	public int count() {
		Long l=(Long) sessionFactory.getCurrentSession().createQuery("from Forder").uniqueResult();
		return l.intValue();
	}

}
